package cn.blog.dao.back;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.blog.dao.conn.DataManager;
import cn.blog.dao.conn.ParamSet;
import cn.blog.dao.conn.RowDatas;
import cn.blog.entity.origin.ManagePeople;
import cn.blog.entity.origin.User;

/**
 * 管理员管理DAO层
 * @author zjk
 *
 */
public class ManagePeopleDao extends DataManager{
	private RowDatas<ManagePeople> manage;//用户对象
	private RowDatas<String> manaName;//管理员类型
	
	/**
	 * 无参构造，初始化
	 */
	public ManagePeopleDao(){
		manage = new ManageData();
		manaName = new ManaNameData();
	}
	/**
	 *1. 查询后台管理员
	 * @return
	 */
	public List<ManagePeople> getManaName(){
		String sql = "SELECT * FROM tb_managepeople";
		return queryList(sql, manage);
		
	}
	/**
	 * 2.添加管理员
	 * @param manaName
	 * @return
	 */
	public int addManaName(String account, String manaName,String password,String phone){
		String sql = "insert into tb_managepeople (mana_account,mana_name,mana_password,mana_phone) values(?,?,?,?)";
		return updateExecuted(sql, new ParamSet(account,manaName,password,phone));
		}
	/**
	 * 3.根据管理员id删除管理员
	 * @param id
	 * @return
	 */
	public int delEmployee(int id){
		String sql = "DELETE FROM tb_managepeople WHERE mana_id= ?";
		return updateExecuted(sql, new ParamSet(id));
	}
	/**
	 * 获取管理员数据
	 * @author zjk
	 *
	 */
	public class ManageData implements RowDatas<ManagePeople>{

		@Override
		public ManagePeople getRowData(ResultSet rs) throws SQLException {
			ManagePeople mp = new ManagePeople();
			mp.setManaId(rs.getInt(1));
			mp.setManaAccont(rs.getString(2));
			mp.setManaName(rs.getString(3));
			mp.setManaPassword(rs.getString(4));
			mp.setManaPhone(rs.getString(5));
			return mp;
		}
		
	}
	
	public class ManaNameData implements RowDatas<String>{

		@Override
		public String getRowData(ResultSet rs) throws SQLException {
			// TODO Auto-generated method stub
			return rs.getString(1);
		}
		
	}
}
